<?php
Authenticate::requireUser();
if($_SERVER['REQUEST_METHOD']=='POST'){
	$db = Db::getInstance();
	$db->autocommit(false);
	try {
		$query = sprintf("INSERT INTO Topic(name,detail,accountId,status) VALUES('%s','%s','%s',1)", $db->real_escape_string($_POST['name']), $db->real_escape_string($_POST['detail']), Authenticate::getId());
		if(!$db->query($query)){
			throw new Exception($db->error);
		}
		$db->commit();
		header("Location: old.php?page=user/qa");
	} catch(Exception $ex) {
		$db->rollback();
		Log::error($ex);
	}
}
else if($_SERVER['REQUEST_METHOD']=='GET'){
	View::display('user/newq');
}
